package com.liuxin.zhiyuan.shujuzhongxin.service.impl;

import com.liuxin.zhiyuan.shujuzhongxin.domain.dto.VolunteerRecommendationDTO;
import com.liuxin.zhiyuan.shujuzhongxin.mapper.VolunteerRecommendationMapper;
import org.springframework.stereotype.Service;
import java.util.Map;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.liuxin.common.utils.PageUtils;
import com.liuxin.common.utils.Query;

import com.liuxin.zhiyuan.shujuzhongxin.domain.po.VolunteerRecommendationEntity;
import com.liuxin.zhiyuan.shujuzhongxin.service.VolunteerRecommendationService;


@Service("volunteerRecommendationService")
public class VolunteerRecommendationServiceImpl extends ServiceImpl<VolunteerRecommendationMapper, VolunteerRecommendationEntity> implements VolunteerRecommendationService {

    @Override
    public PageUtils queryPage(Map<String, Object> params) {
        IPage<VolunteerRecommendationDTO> page = new Query<VolunteerRecommendationDTO>().getPage(params);
        IPage<VolunteerRecommendationDTO> resultPage = this.baseMapper.queryPage(page);
        return new PageUtils(resultPage);
    }

    @Override
    public VolunteerRecommendationEntity getInfoById(Integer id) {
        QueryWrapper<VolunteerRecommendationEntity> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("id", id);
        VolunteerRecommendationEntity result = this.getOne(queryWrapper);
        return result;
    }

    @Override
    public VolunteerRecommendationEntity getByIdWithVersion(Integer xueyuanid) {
        QueryWrapper<VolunteerRecommendationEntity> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("xueyuan_id", xueyuanid);
        queryWrapper.orderByDesc("version");
        queryWrapper.last("limit 1");
        VolunteerRecommendationEntity result = this.getOne(queryWrapper);
        return result;
    }

}